package model.hospital;

import net.passClass.PassData;

import java.util.TreeSet;

public class Floor implements Comparable<Floor>{
    private int floorNumber;
    private TreeSet<Room> rooms = new TreeSet<>();

    @Override
    public int compareTo(Floor o) {
        return this.floorNumber - o.floorNumber;
    }

    public PassData add(Room room) {
        Room aRoom = new Room(room.getLocation().getRoomNumber());
        if(room.getBeds()==null){
            if(rooms.contains(aRoom)){
                return new PassData(false,null,"房间已存在，新增失败");
            }
            rooms.add(room);
            return new PassData(true,null,"房间新增成功");
        }
        if(!rooms.contains(aRoom)){
            rooms.add(aRoom);
        }
        return rooms.ceiling(room).add(room);
    }

    public PassData delete(Room room) {
        Room aRoom = new Room(room.getLocation().getRoomNumber());
        Room theRoom = rooms.ceiling(aRoom);
        System.out.println("theRoom:"+theRoom);
        System.out.println("room:"+room);
        if(!rooms.contains(theRoom)){
            return new PassData(false, null,"房间不存在，删除失败");
        }
        if (room.getBeds()==null){     //即删除房间
            if(!(theRoom.getBeds() == null || theRoom.getBeds().isEmpty())){
                return new PassData(false,null,"房间中存在床位，删除失败");
            }
            rooms.remove(theRoom);
            return new PassData(true,null,"房间删除成功");
        }

        return theRoom.delete(room);        //删除房间内对象
    }

    public Floor(int floorNumber) {
        this.floorNumber = floorNumber;
    }

    public Floor() {
    }

    public int getFloorNumber() {
        return floorNumber;
    }

    public void setFloorNumber(int floorNumber) {
        this.floorNumber = floorNumber;
    }

    public TreeSet<Room> getRooms() {
        return rooms;
    }

    public void setRooms(TreeSet<Room> rooms) {
        this.rooms = rooms;
    }
}
